package com.design.proxy.gpproxy.proxy;

import com.design.proxy.gpproxy.client.Person;

import java.lang.reflect.Method;

public class GPMeipo implements GPInvocationHandler {

    private Person target;

    public Person getInstance(Person target) {
        this.target = target;
        Class<?> clazz = target.getClass();
        return (Person) GPProxy.newProxyInstance(new GPClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object invoke = method.invoke(this.target, args);
        after();
        return invoke;

    }

    private void after() {
        System.out.println("双方同意：开始交往");
    }

    private void before() {
        System.out.println("我是媒婆，已经收集到你的需求，开始物色");
    }
}
